package com.ht.aems.fesmodel;

import java.util.HashMap;
import java.util.Map;

/**
 * class DefaultUnit
 * @author Dong Shufeng
 * Date: 2006-3-11
 * @version 1.0
 */
public class DefaultUnit extends AbstractUnit implements IUnitManager {

    private Map<String, AbstractUnit> units = new HashMap<String, AbstractUnit>();

    public DefaultUnit(int id, String name) {
        super(id, name);
    }

    public DefaultUnit() {
        this("");
    }

    public DefaultUnit(String name) {
        super(-1, name);
    }

    public DefaultUnit(int id, String name, int parentUnitId) {
        super(id, name, parentUnitId);
    }

    public AbstractUnit getUnit(String name) {
        return units.get(name);
    }

    public void addUnit(AbstractUnit unit) {
        unit.setParentUnitId(this.getId());
        units.put(unit.getName(), unit);
    }

    public boolean contains(String unitName) {
        return units.containsKey(unitName);
    }

    public AbstractUnit removeUnit(String name) {
        return units.remove(name);
    }

    public boolean modifyUnit(String name, AbstractUnit unit) {
        if(contains(name))
            units.put(name, unit);
        return true;
    }

    public Map<String,AbstractUnit> getAllUnits() {
        return units;
    }

    public void addAll(Map<String, AbstractUnit> allUnits) {
        units.putAll(allUnits);
    }

    public String toString() {
        return name;
    }
}
